package com.jz.community.moduleshopping.address.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.utils.CharacterUtils;
import com.jz.community.basecomm.utils.ConverterUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.confirmOrder.bean.ShopSelfAddressInfo;

import java.util.List;
import java.util.Locale;

/**
 * 附近自提点
 */
public class NearShopListAdapter extends BaseQuickAdapter<ShopSelfAddressInfo.EmbeddedBean.ContentBean, BaseViewHolder> {
    private String type;
    private TextView shopListName;

    public NearShopListAdapter(int layoutResId, @Nullable List<ShopSelfAddressInfo.EmbeddedBean.ContentBean> data, String type) {
        //type2仅自提，1附近自提（za展示三个）
        super(layoutResId, data);
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, ShopSelfAddressInfo.EmbeddedBean.ContentBean item) {
        if (item.isChoose()) {
            shopListName = helper.getView(R.id.tv_near_shop_list_name);
            shopListName.setTextColor(Color.parseColor("#f2383b"));
            shopListName.setText(item.getName());
        } else {
            shopListName = helper.getView(R.id.tv_near_shop_list_name);
            shopListName.setTextColor(Color.parseColor("#23232e"));
            shopListName.setText(item.getName());
        }
        if (helper.getAdapterPosition() == 0) {
            helper.setText(R.id.tv_near_shop_list_address, "推荐自提   " + item.getAddress() + "（" + item.getContact_tel() + "）");
        } else {
            helper.setText(R.id.tv_near_shop_list_address, item.getAddress() + "（" + item.getContact_tel() + "）");
        }

        if (!Preconditions.isNullOrEmpty(item.getDistance())) {
            if (ConverterUtils.toFloat(item.getDistance()) < 1000) {
                helper.setText(R.id.tv_near_shop_list_dis, "距" + CharacterUtils.regularizePrice(ConverterUtils.toFloat(item.getDistance())) + "m");
            } else {
                String dis = CharacterUtils.regularizePrice(ConverterUtils.toFloat(item.getDistance()) / 1000);
                helper.setText(R.id.tv_near_shop_list_dis, "距" + dis + "km");
            }
        }
        TextView recommend = helper.getView(R.id.tv_near_shop_list_recommend);
        if (helper.getAdapterPosition() == 0) {
            recommend.setVisibility(View.VISIBLE);
        } else {
            recommend.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        if ("2".equals(type)) {
            return super.getItemCount();
        } else {
            if (mData.size() >= 3) {
                return 3;
            } else {
                return super.getItemCount();
            }
        }
    }
}
